﻿using System.Windows;
using Microsoft.Phone.Controls;
using System.Windows.Media.Animation;
using System;
using System.Windows.Threading;

namespace WPNEXT.Views
{
    public partial class AnimationDemoPage : PhoneApplicationPage
    {
        private DispatcherTimer timer;
        public AnimationDemoPage()
        {
            InitializeComponent();
            timer = new DispatcherTimer();
            timer.Interval = TimeSpan.FromMilliseconds(1000);
            timer.Tick += new EventHandler(timer_Tick);
            timer.Start();
        }

        void timer_Tick(object sender, EventArgs e)
        {
            CreateStory().Begin();
        }

        private void Play_Click(object sender, RoutedEventArgs e)
        {
            if (timer != null)
            {
                timer.Stop();
            }
        }

        private Storyboard CreateStory()
        {
            Storyboard st = new Storyboard();
            DoubleAnimationUsingKeyFrames da = new DoubleAnimationUsingKeyFrames();
            EasingDoubleKeyFrame ed = new EasingDoubleKeyFrame{KeyTime=TimeSpan.FromMilliseconds(0),Value=1};
            EasingDoubleKeyFrame ed2= new EasingDoubleKeyFrame{KeyTime=TimeSpan.FromMilliseconds(1000),Value=18};
            da.KeyFrames.Add(ed);
            da.KeyFrames.Add(ed2);

            Storyboard.SetTarget(da,this.imageSequence);
            Storyboard.SetTargetProperty(da,new PropertyPath("(ImageSequence.CurrentImgNum)"));

            st.Children.Add(da);
            return st;
        }
    }
}